package com.siyue.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.siyue.dao.DAOFactory;
import com.siyue.dao.MemberGradeDAO;
import com.siyue.util.DataBase;

public class SysMemberGradeServlet extends TopServlet {

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method= request.getParameter("method");
		
		try{
			MemberGradeDAO memberGradeDao= DAOFactory.getMemberGradeDAO();
			
			if("list".equals(method)){
				List listTemp=memberGradeDao.getMemberGrades();
				request.setAttribute("gradeList",listTemp);
				this.forward(request, response, "/secure/memberGrade/gradeList.jsp");				
			}
			DataBase.commit();
		}catch(Exception e){
			DataBase.rollback();
			e.printStackTrace();
		}
		DataBase.releaseConnection();		
		
	}

}
